<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>四上数学</title>
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/vue/2.2.4/vue.min.js"></script>
<style>
body{
    font-size:16px;
}
.t-item{
    padding-bottom:20vh;
}
.center{
    text-align: center;
}
.mb30{
    padding-bottom:30px;
}
.fuhao{
    font-weight: bold;
    margin:0 2px;
}
.flex{
    display: flex;
    align-items: center;
    margin-bottom:8px;
}
.flex1{
    flex:1;
}
input.form-control{
    width:auto;
}
</style>
</head>
<body>
<div class="container" id="app">
    <h3 class="center">四上数学</h3>
    <form class="mb30">
        <h4 class="center">题目设置</h4>
        <div class="flex">
            <label class="flex1">三位数除两位数</label>
            <input type="number" class="form-control" v-model="f.div">
        </div>
        <div class="flex">
            <label class="flex1">三位数乘两位数</label>
            <input type="number" class="form-control" v-model="f.mul">
        </div>
        <div class="flex">
            <label class="flex1">简便运算</label>
            <input type="number" class="form-control" v-model="f.simple">
        </div>
        <button class="btn btn-success btn-block" type="button" @click="init">生成题目</button>
    </form>

    <div class="row">
        <div class="col-xs-6 t-item" v-for="item in list">
            <span v-for="(v,i) in item.exp" :class="{fuhao:is_sign(v)}">{{v}}</span>
            <br v-if="item.exp.length>3">
            =
            <span v-show="show">{{item.r}}</span>
        </div>
    </div>
    <p class="center mb30">
        <button class="btn btn-default" @click="show=!show">{{show?'隐藏':'显示'}}答案</button>
    </p>
</div>
</body>
</html>
<script src="./assets/fun.js"></script>
<script src="./math-simple.js"></script>
<script>
/*
四年级寒假作业
2道乘法竖式（三位数乘两位数），
2道除法竖式（三位数除两位数），
2道递等式计算（包含简便运算）。
TODO:简单运算可以考虑是否混合不能简便的情况
*/
new Vue({
    el:"#app",
    data:{
        list:[],
        show:false,
        f:{
            mul:2,
            div:2,
            simple:2,
        }
    },
    created(){
        this.init();
    },
    methods:{
        init(){
            let list=this.three_div_two(this.f.div);
            list=list.concat(this.three_mul_two(this.f.mul));
            let arr=mathSimple.run(this.f.simple);
            list=list.concat(arr);
            this.list=list;
        },
        is_sign(v){
            let sign=["÷","×","+","-"];
            return sign.indexOf(v)>-1;
        },
        three_mul_two(len=2){
            let list=[];
            for(let i=0;i<len;i++){
                let a=fun.rand(100,999);
                let b=fun.rand(10,99);
                let r=a*b;
                list.push({
                    exp:[a,"×",b],
                    r,
                })
            }
            return list;
        },
        three_div_two(len=2){
            let list=[];
            for(let i=0;i<len;i++){
                let a=fun.rand(100,999);
                let b=fun.rand(10,99);
                let r=Math.floor(a/b);
                let ys=a%b;
                if(ys>0){
                    r=r+"......"+ys;
                }
                list.push({
                    exp:[a,"÷",b],
                    r,
                })
            }
            return list;
        }
    }
})
</script>